<?php

use app\assets\ApiAsset;
use app\assets\LayerAsset;
use app\assets\TableAsset;
use app\widgets\LinkPager;
use app\widgets\ManagerTableOp;
use yii\helpers\Html;
use yii\helpers\Url;
use app\models\KeyMap;
/**
 * @var $this yii\web\View
 * @var $profitList app\models\AgentProfit[]
 * @var $pagination yii\data\Pagination
 */

ApiAsset::register($this);
LayerAsset::register($this);
TableAsset::register($this);

$this->title = '代理收益列表';
$this->params['breadcrumbs'][] = '财务管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo Html::beginForm('?', 'get', ['class'=>'form-inline']);?>
<div class="form-group">
    <label for="search_trade_no" class="sr-only">Trade_no</label>
    <?php echo Html::textInput('search_trade_no', Yii::$app->request->get('search_trade_no'), ['id'=>'search_trade_no', 'class'=>'form-control', 'placeholder'=>'搜索交易编号', 'style' => 'width:120px;']);?>
</div>
<div class="form-group">
    <button class="btn btn-primary btn-sm">搜索</button>
</div>
<?php echo Html::endForm();?>
<table class="table table-striped table-bordered table-hover">
    <thead>
    <tr>
        <th class="center">
            <label class="pos-rel">
                <input type="checkbox" class="ace" />
                <span class="lbl">编号</span>
            </label>
        </th>
        <th>代理商</th>
        <th>套餐</th>
        <th>充值时长</th>
        <th>交易编号</th>
        <th>收益金额</th>
        <th>时间</th>
        <th>操作</th>
    </tr>
    </thead>

    <tbody>
    <?php foreach ($profitList as $profit) {?>
        <tr>
            <td class="center"><label class="pos-rel"><input type="checkbox" class="ace" value="<?php echo $profit->id;?>" /><span class="lbl"><?php echo $profit->id;?></span></label></td>
            <td><?php echo $profit->agent->username;?></td>
            <td><?php echo $profit->package->name;?></td>
            <td><?php echo $profit->recharge->term_length, KeyMap::getValue('card_term_length_unit', $profit->recharge->term_length_unit);?></td>
            <td><?php echo $profit->recharge->trade_no; ?></td>
            <td><?php echo $profit->money;?></td>
            <td><?php echo Yii::$app->formatter->asDatetime($profit->create_time);?></td>
            <td><?php echo ManagerTableOp::widget(['items' => [
                    ['icon' => 'fa fa-info-circle','onclick' => 'view('.$profit->user_card_recharge_id.')','btn_class' => 'btn btn-xs btn-default','tip' => '详情'],
                ]]);?>
            </td>
        </tr>
    <?php }?>
    </tbody>
</table>
<?php echo LinkPager::widget(['pagination' => $pagination]);?>
<script>
/**
    * 弹出卡充值详情   
     */
    function view(id){
        url = "<?php echo Url::to(['/agent/profit/recharge-view']);?>?id="+id;
        layer.open({
        type: 2, 
        closeBtn: 2,
        title:'卡充值详情',
        offset: 'auto',
        area: ['750px', '800px'],
        shade: 0.5,
        shadeClose:true,
        content: url 
        }); 
    }
</script>